package com.lxw.study.behavioral.status.case1;

public class ElevatorContext {
    private ElevatorState currentState;

    // 初始化为关门状态
    public ElevatorContext() {
        currentState = new CloseDoorState();
    }

    public void setState(ElevatorState state) {
        currentState = state;
    }

    public void openDoor() {
        currentState.openDoor();
        if (currentState instanceof CloseDoorState) {
            setState(new OpenDoorState());
        }
    }

    public void closeDoor() {
        currentState.closeDoor();
        if (currentState instanceof OpenDoorState) {
            setState(new CloseDoorState());
        }
    }

    public void moveUp() {
        currentState.moveUp();
    }

    public void moveDown() {
        currentState.moveDown();
    }
}
